#include "RingQueue.hpp"
#include "Task.hpp"
#include <iostream>
#include <pthread.h>
#include <unistd.h>


void* Productor(void* args)
{
    RingQueue<Task> *rq = static_cast<RingQueue<Task> *>(args);
    while (true)
    {
        sleep(1);
        int x = rand() % 10 + 1;
        int y = rand() % 10 + 1;
        
        Task t(x,y);
        rq->Push(t);
        std::cout<<t.debug()<<std::endl;;
    }
    
}

void* Consumer(void* args)
{
    RingQueue<Task> *rq = static_cast<RingQueue<Task> *>(args);
    while(true)
    {
        //sleep(1);
        Task t;
        rq->Pop(&t);
        t.Excute();
        std::cout<<t.result()<<std::endl;
    }
}


int main()
{
    srand(time(nullptr) ^ getpid());
    RingQueue<Task> *rq = new RingQueue<Task>(5);
    
    pthread_t c,p;

    pthread_create(&p,nullptr,Productor,rq);
    pthread_create(&c,nullptr,Consumer,rq);



    pthread_join(p,nullptr);
    pthread_join(c,nullptr);

    return 0;
}